#pragma once

#include <fstream>
#include <iostream>
#include <cmath>
#include "../../include/detection.hpp"
#include "../tracking.cpp"


class Slow_zone_Detection
{
public:
  int dump_num = 1;
  int slow_zone_time = 0;
  void reset()
  {
    dump_num = 1;
  }
  
  void clear()
  {
    dump_num = 0;
  }
  
  bool Detection(vector<PredictResult> predict)
  {
    for (uint16_t i = 0; i < predict.size(); i++)
        {
            if (predict[i].label == LABEL_BUMP && (predict[i].y+(int)predict[i].height/2)>((float)ROWCOMMON/1.8))
            {
                slow_zone_time = 10;
                detect_dump_center = predict[i].x+(int)predict[i].width/2;
                return true;
            }
        }
    slow_zone_time && slow_zone_time--;
    return false;
  }
  
  void slow_zone_deal(TrackRecognition *tracker)
  {
    POINT slow_zone_start_point = tracker->start_point;
    slow_zone_start_point.x = detect_dump_center;
    slow_zone_start_point.y = 80;
    tracker->start_point = slow_zone_start_point;
    tracker->clear_edge();
    tracker->trackRecognition_grow();
    tracker->get_valid_point();
    tracker->cal_error();
    tracker->track_error *= 2.1;
  }
private:
  int detect_dump_center = 160;
};